package com.sunfeng.chap5.selectkey;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.Set;

public class Test101 {
    public static void main(String[] args) throws IOException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();

        serverSocketChannel.bind(new InetSocketAddress("localhost", 8888));
        serverSocketChannel.configureBlocking(false);
        Selector selector = Selector.open();
        serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
        boolean isRun = true;
        while (isRun == true) {
            int select = selector.select();
            Set<SelectionKey> selectionKeySet = selector.keys();
            Set<SelectionKey> selectionKeySet1 = selector.selectedKeys();
            System.out.println(select);
            System.out.println(selectionKeySet);
            System.out.println(selectionKeySet1);
        }
        serverSocketChannel.close();
    }
}
